<div ng-show="vm.notFoundMessage" class="alert alert-warning" role="alert">{{ vm.notFoundMessage }}</div>
<div ng-show="vm.uploaded" class="alert alert-success" role="alert" style="margin-bottom: 0px;"><strong>{{ 'TORRENTS.UPLOAD_SUCCESS_TITLE' | translate }}</strong><br />{{ 'TORRENTS.UPLOAD_SUCCESS_BODY' | translate }}</div>

<br />

<div class="row row-centered ng-cloak" ng-hide="vm.notFoundMessage">

	<loading-indicator hide="vm.torrent || vm.notFoundMessage"></loading-indicator>

	<movie-info movie-data="::vm.movieData" ng-show="vm.movieData.title != null && vm.torrent.tv_programid == 0" trailer="true"></movie-info>

	<swetv-info torrent="::vm.torrent" tv-channel="::vm.tvChannel" ng-show="vm.torrent.tv_programid > 0"></swetv-info>

	<div ng-show="vm.movieData.title != null || vm.torrent.tv_programid > 1">
		<br />
	</div>

	<div class="table-responsive noborder col-md-9 col-centered" ng-class="{'col-lg-12': vm.showPeers || vm.showSnatchLog}" ng-show="vm.torrent">
		<table class="table" cellpadding="15">
			<tr>
				<td class="text-right tdBold hidden-xs alignMiddle" style="width: 130px;" translate="TORRENTS.THIS_TORRENT"></td>
				<td class="text-left alignMiddle">
					<table class="table table-striped table-hover table-nowrap noshadow">
						<tr>
							<td style="width: 57px;">
								<img class="categoryImage category{{ ::vm.torrent.category }}" />
							</td>
							<td class="text-left vert-align">
								<torrent torrent="vm.torrent" viewing-torrent="{{ ::vm.torrent.id }}"></torrent>
							</td>
							<td style="width: 168px; vertical-align: middle;">
				    			<a class="noBorder" target="_self" href="/api/v1/torrents/download/{{ ::vm.torrent.id }}/{{ ::vm.currentUser.passkey }}" style="float: right;">
				    				<button class="btn btn-default btn-xs"><i class="fa fa-link"></i></button>
				    			</a>
				    			<a class="noBorder" target="_self" href="/api/v1/torrents/download/{{ ::vm.torrent.id }}" style="float: right;">
				    				<button class="btn btn-default btn-xs"><i class="fa fa-download"></i> {{ 'TORRENTS.DOWNLOAD' | translate }}</button>
								</a>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr ng-show="vm.request">
				<td class="text-right tdBold hidden-xs" translate="REQUESTS.FILLED"></td>
				<td class="text-left">
					"{{ ::vm.request.request }}<span ng-show="::vm.request.season > 0"> ({{ 'REQUESTS.REQUESTS' | translate }} {{ ::vm.request.season}})</span>" {{ 'REQUESTS.WAS_REQUESTED_BY' | translate }} <user user="::vm.request.user"></user> <span translate="REQUESTS.WITH_VOTES_REWARD" translate-value-votes="{{ ::vm.request.votes }}" translate-value-reward="{{ ::vm.request.reward }}"></span>
					<button class="btn btn-default btn-xs" ui-sref="requests.request({id: vm.request.id, slug: vm.request.slug })" translate="REQUESTS.SHOW"></button>
				</td>
			</tr>
			<tr ng-show="vm.relatedTorrents.length > 0">
				<td class="text-right tdBold hidden-xs" translate="TORRENTS.MORE_RELEASES"></td>
				<td class="text-left">
					<div style="max-height: 400px; overflow-y: auto; overflow-x: hidden;">
						<torrents-table torrents="vm.relatedTorrents" show-header="false" col-download="true"></torrents-table>
					</div>
				</td>
			</tr>
			<tr ng-show="vm.torrent.descr">
				<td class="text-right tdBold hidden-xs" translate="TORRENTS.NFO"></td>
				<td class="text-left"><pre style="max-height: 300px; white-space: pre-wrap;" ng-bind-html="::vm.torrent.descr | bbCode"></pre></td>
			</tr>
			<tr ng-show="vm.packContent.length > 0">
				<td class="text-right tdBold hidden-xs" translate="TORRENTS.PACK_CONTENT"></td>
				<td class="text-left">
					<div ng-repeat="folder in ::vm.packContent" style="font-weight: bold;">
						{{ ::folder.filename }}
					</div>
					<div ng-if="vm.currentUser.class >= 8">
						<button class="btn btn-default btn-xs" ng-click="vm.multiDelete()" ng-disabled="vm.deletingPackFiles"><i class="fa fa-user-secret"></i> {{ 'TORRENTS.DELETE_ALL' | translate }}</button>
					</div>
				</td>
			</tr>
			<tr ng-show="vm.torrent.category > 3 && vm.torrent.category < 8">
				<td class="text-right tdBold hidden-xs" translate="TORRENTS.SWE_SUBTITLES"></td>
				<td class="text-left">
					<table ng-show="vm.subtitles.length > 0" class="table table-striped table-hover table-nowrap" style="margin-bottom: 6px !important;">
						<tr ng-repeat="subtitle in vm.subtitles">
							<td style="width: 35px;"><img src="/img/icons/subfile.png" alt="subtitle" style="width: 29px;" /></td>
							<td class="alignMiddle">
								<div class="ellipsis">
									<a target="_self" ng-href="/api/v1/subtitles/{{ ::subtitle.id }}/download">{{ ::subtitle.filename }}</a>
								</div>
								<span class="label label-warning" ng-show="subtitle.quality == 'custom'" translate="TORRENTS.SUBTITLE_QUALITY_CUSTOM"></span>
								<span class="label label-success" ng-show="subtitle.quality == 'retail'" translate="TORRENTS.SUBTITLE_QUALITY_RETAIL"></span>
							</td>
							<td style="width: 150px;" ng-show="subtitle.user" class="alignMiddle"><user user="subtitle.user" show-class="false"></user></td>
							<td ng-show="vm.currentUser.class >= 8 || vm.currentUser.id == subtitle.user.id" style="width:80px;" class="alignMiddle"><button ng-click="vm.deleteSubtitle(subtitle)" class="btn btn-xs btn-default"><i class="fa fa-trash-o"></i> {{ 'BUTTONS.DELETE' | translate }}</button></td>
							<td style="width:125px;" class="alignMiddle"><report-button type="subtitle" id="::subtitle.id" body="::subtitle.filename"></report-button></td>
						</tr>
					</table>
					<div class="text-center">
						<button ng-click="vm.showSubtitleUpload =! vm.showSubtitleUpload" class="btn btn-xs btn-default"><i class="fa fa-upload"></i> {{ 'TORRENTS.UPLOAD_SUBTITLE' | translate }} (+<b>2p</b>)</button>
					</div>
					<div class="text-center" ng-class="{'hidden': !vm.showSubtitleUpload}">
						<div class="input-group center-block">
							<select class="form-control" ng-model="vm.subtitleQuality">
								<option value="" translate="TORRENTS.CHOOSE_SUB_QUALITY"></option>
								<option value="custom" translate="TORRENTS.SUBTITLE_QUALITY_CUSTOM"></option>
								<option value="retail" translate="TORRENTS.SUBTITLE_QUALITY_RETAIL"></option>
							</select>
							<input type="file" class="form-control" file-model="vm.subFile" file-changed="vm.subtitleFileChanged()" />
						</div>
					</div>
				</td>
			</tr>
			<tr ng-if="vm.torrent.imdbid">
				<td class="text-right tdBold hidden-xs alignMiddle" translate="WATCHER.TITLE"></td>
				<td>
					<watch-button torrent-id="::vm.torrentId" torrent-category="vm.torrent.category" movie-data="vm.movieData"></watch-button>
				</td>
			</tr>
			<tr ng-if="vm.torrent.imdbid">
				<td class="text-right tdBold hidden-xs alignMiddle" translate="WATCHER.WATCH_SUBTITLES"></td>
				<td>
					<button ng-disabled="vm.watchingSubtitle" class="btn btn-default btn-xs" ng-click="vm.addSubtitleWatch()"><i class="fa fa-envelope-o fa-fw"></i> {{ 'WATCHER.PM_WATCH_SUBTITLES' | translate }}</button>
				</td>
			</tr>
			<tr ng-show="vm.torrent.seeders <= 3 && (vm.torrent.added | dateDiff) < -86400000">
				<td class="text-right tdBold hidden-xs alignMiddle" translate="TORRENTS.REQUEST_SEED"></td>
				<td>
					<button class="btn btn-default btn-xs" ng-click="vm.requestReseed()"><i class="fa fa-retweet"></i> {{ 'TORRENTS.REQUEST_SEED' | translate }} (<b>5p</b>)</button>
				</td>
			</tr>
			<tr>
				<td class="text-right tdBold hidden-xs alignMiddle" translate="TORRENTS.UPLOADED_WHEN"></td>
				<td class="text-left alignMiddle">{{ ::vm.torrent.added }} <span ng-hide="vm.torrent.preDate == '1970-01-01 01:00:00'" translate="TORRENTS.AFTER_PRE" translate-value-time="{{::vm.torrent.added | dateDifference:vm.torrent.preDate }}"></span></td>
			</tr>
			<tr>
				<td class="text-right tdBold hidden-xs alignMiddle" translate="TORRENTS.SIZE"></td>
				<td class="text-left">{{ ::vm.torrent.size | prettysize }}</td>
			</tr>
			<tr>
				<td class="text-right tdBold hidden-xs alignMiddle" translate="TORRENTS.DOWNLOADED"></td>
				<td class="text-left" translate="TORRENTS.TIMES_COMPLETED" translate-value-x="{{ ::vm.torrent.times_completed }}"></td>
			</tr>
			<tr>
				<td class="text-right tdBold hidden-xs alignMiddle" translate="TORRENTS.UPLOADER"></td>
				<td class="text-left">
					<user user="::vm.torrent.user"></user>
					<a ng-show="vm.currentUser.class >= 8 || vm.currentUser.id == vm.torrent.user.id" ui-sref="editTorrent({id: vm.torrent.id, name: vm.torrent.name})">
						<button class="btn btn-default btn-xs"><i class="fa fa-cog"></i> {{ 'TORRENTS.EDIT' | translate }}</button>
					</a>
				</td>
			</tr>
			<tr>
				<td class="text-right tdBold hidden-xs alignMiddle" translate="TORRENTS.BOOKMARK"></td>
				<td class="text-left">
					<bookmark-button torrent="vm.torrent"></bookmark-button>
				</td>
			</tr>
			<tr>
				<td class="text-right tdBold hidden-xs alignMiddle" translate="TORRENTS.REPORT"></td>
				<td class="text-left"><report-button type="torrent" id="vm.torrent.id" body="vm.torrent.name"></report-button></td>
			</tr>
			<tr ng-if="vm.currentUser.class >= 8">
				<td class="text-right tdBold hidden-xs">
					<button class="btn btn-default btn-xs" ng-click="vm.toggleSnatchLog()">
						<i class="fa fa-bars"></i> {{ 'TORRENTS.SHOW_SNATCH' | translate }}
					</button>
				</td>
				<td class="text-left">
					<div ng-show="vm.showSnatchLog && !vm.snatchLog" class="fa-spinner fa-spin fa-3x fa-fw spinner"></div>
					<table class="table table-striped table-hover table-nowrap" ng-show="vm.showSnatchLog && vm.snatchLog">
						<thead>
							<tr>
								<th style="text-align: left;">&nbsp;{{ 'TORRENTS.USERNAME' | translate }}</th>
								<th style="width: 160px;"><a class="whiteLink" href="" ng-click="snatchLogOrderBy='ip'; reverseSort = !reverseSort" translate="TORRENTS.IP_PORT"></a></th>
								<th><a class="whiteLink" href="" ng-click="snatchLogOrderBy='uploaded'; reverseSort = !reverseSort" translate="TORRENTS.UPLOADED"></a></th>
								<th><a class="whiteLink" href="" ng-click="snatchLogOrderBy='downloaded'; reverseSort = !reverseSort" translate="TORRENTS.DOWNLOADED"></a></th>
								<th style="width: 100px;white-space: nowrap;" translate="TORRENTS.START_STOP_FINISHED"></th>
								<th translate="TORRENTS.CLIENT"></th>
								<th><a class="whiteLink" href="" ng-click="snatchLogOrderBy='finishedat'; reverseSort = !reverseSort" translate="TORRENTS.SNATCHED"></a></th>
								<th><a class="whiteLink" href="" ng-click="snatchLogOrderBy='seedtime'; reverseSort = !reverseSort" translate="TORRENTS.SEED_TIME"></a></th>
							</tr>
						</thead>
						<tbody>
							<tr ng-repeat="snatch in vm.snatchLog | orderBy:snatchLogOrderBy:reverseSort track by snatch.id ">
								<td class="text-left"><user user="::snatch.user"></user></td>
								<td>{{ ::snatch.ip }}:{{ ::snatch.port }}</td>
								<td class="text-center">{{ ::snatch.uploaded | prettysize }}</td>
								<td class="text-center">{{ ::snatch.downloaded | prettysize }}</td>
								<td class="text-center">{{ ::snatch.timesStarted }}/{{ ::snatch.timesStopped }}/{{ ::snatch.timesCompleted }}</td>
								<td class="text-center">{{ ::snatch.agent | prettyAgent }}</td>
								<td class="text-center">{{ ::snatch.finishedat | dateDifference }} sedan</td>
								<td class="text-center">{{ ::snatch.seedtime*1000 | dateDifference:0 }}</td>
							</tr>
						</tbody>
					</table>
				</td>
			</tr>
			<tr>
				<td class="text-right tdBold hidden-xs">
					<button class="btn btn-default btn-xs" ng-click="vm.toggleFiles()">
						<i class="fa fa-bars"></i> {{ 'TORRENTS.SHOW_FILELIST' | translate }}
					</button>
				</td>
				<td class="text-left">
					<span translate="TORRENTS.NUM_FILES" translate-value-x="{{ ::vm.torrent.numfiles }}"></span>
					<div ng-show="showFiles && !files" class="fa-spinner fa-spin fa-3x fa-fw spinner"></div>
					<table class="table table-striped table-hover table-nowrap" ng-show="vm.showFiles && vm.files">
						<thead>
							<tr>
								<th class="text-left">&nbsp;{{ 'TORRENTS.FILE_NAME' | translate }}</th>
								<th style="width: 100px;" class="text-left" translate="TORRENTS.SIZE"></th>
							</tr>
						</thead>
						<tbody>
							<tr ng-repeat="file in ::vm.files">
								<td style="text-align: left;">{{ ::file.filename }}</td>
								<td style="width: 100px;">{{ ::file.size | prettysize }}</td>
							</tr>
						</tbody>
					</table>
				</td>
			</tr>
			<tr>
				<td class="text-left tdBold hidden-xs">
					<button class="btn btn-default btn-xs" ng-click="vm.togglePeers()">
						<i class="fa fa-bars"></i> {{ 'TORRENTS.SHOW_TRANSFERS' | translate }}
					</button>
				</td>
				<td class="text-left">
					<a id="seeders" name="seeders"></a>
					<span translate="TORRENTS.TRANSFERS_ROW" translate-value-seeders="{{ ::vm.torrent.seeders }}" translate-value-leechers="{{ ::vm.torrent.leechers }}" translate-value-total="{{ ::vm.torrent.seeders + vm.torrent.leechers }}"></span>
					<div ng-show="vm.showPeers && !vm.seeders" class="fa-spinner fa-spin fa-3x fa-fw spinner"></div>
					<torrent-peers peers="::vm.seeders" ng-show="vm.seeders && vm.showPeers" my-user-id="{{ vm.currentUser.id }}"></torrent-peers>
					<a id="leechers" name="leechers"></a>
					<torrent-peers peers="::vm.leechers" torrent-size="vm.torrent.size" ng-show="vm.leechers && vm.showPeers" my-user-id="{{ vm.currentUser.id }}"></torrent-peers>
				</td>
			</tr>
		</table>
	</div>

	<a id="comments" name="comments" style="display: inline-block;"></a>
	<div ng-show="vm.comments">
		<h2 translate="COMMENTS.TITLE"></h2>

		<uib-pagination max-size="10" items-per-page="vm.itemsPerPage" total-items="vm.totalItems" ng-model="vm.currentPage" ng-click="vm.loadComments()" previous-text="{{ 'PAGER.PREVIOUS' | translate }}" next-text="{{ 'PAGER.NEXT' | translate }}" boundary-links="true" first-text="{{ 'PAGER.FIRST' | translate }}" last-text="{{ 'PAGER.LAST' | translate }}" ng-hide="vm.comments.length == 0"></uib-pagination>

		<div class="col-md-10 col-md-push-1" ng-show="vm.comments">
			<posts posts="vm.comments" delete-post="vm.deleteComment(post)" edit-obj="vm.editObj" on-quote="vm.quotePost(post)" goto-anchor="vm.gotoPostAnchor(postId)" edit-post="vm.editPost(post)" abort-edit="vm.abortEdit()" save-edit="vm.saveEdit(post)" ng-hide="vm.comments.length == 0"></posts>
			<div id="newComment">
				<div class="text-center">
					<h3 translate="COMMENTS.WRITE"></h3>
					<div class="form-group col-md-8 col-md-push-2">
						<textarea class="form-control" rows="6" id="postText" ng-model="vm.postText" placeholder="{{ 'COMMENTS.WRITE_PLACEHOLDER' | translate }}"></textarea>
					</div>
					<div class="clearfix"></div>
					<button ng-show="vm.postStatus == 0" class="btn btn-primary" ng-click="vm.savePost()" translate="COMMENTS.POST"></button>
					<button ng-show="vm.postStatus == 1" class="btn btn-primary disabled"><i class="fa fa-spinner fa-spin"></i></button>
				</div>
				<br />
				<uib-alert type="{{ vm.alert.type }}" close="vm.closeAlert()" ng-show="vm.alert != null">
					{{ vm.alert.msg }}
				</uib-alert>
			</div>
		</div>

		<div class="clearfix"></div>

		<uib-pagination max-size="10" items-per-page="vm.itemsPerPage" total-items="vm.totalItems" ng-model="vm.currentPage" ng-click="vm.loadComments()" previous-text="{{ 'PAGER.PREVIOUS' | translate }}" next-text="{{ 'PAGER.NEXT' | translate }}" boundary-links="true" first-text="{{ 'PAGER.FIRST' | translate }}" last-text="{{ 'PAGER.LAST' | translate }}" ng-hide="vm.comments.length == 0"></uib-pagination>
	</div>

</div>
